package cn.zy.company.service;

import cn.zy.company.dao.MemberDao;
import cn.zy.company.entity.Member;
import cn.zy.company.entity.PageObj;

import java.util.List;

public class MemberService {
    MemberDao memberDao = new MemberDao();

    public void add(Member member) throws Exception {
        memberDao.add(member);
    }

    public void delete(Integer id) throws Exception {
        memberDao.delete(id);
    }

    public void update(Member member) throws Exception {
        memberDao.update(member);
    }

    public Member findById(Integer id) throws Exception {
        return memberDao.findById(id);
    }

    public List<Member> findAll() throws Exception {
        return memberDao.findAll();
    }

    public PageObj<Member> findAll(PageObj<Member> pageObj) throws Exception {
        List<Member> list = memberDao.findAll(pageObj.getPage(), pageObj.getSize());
        pageObj.setList(list);
        long l = memberDao.countAll();
        pageObj.setCount(l);
        Integer size = pageObj.getSize();
        long l1 = l % size != 0 ? (l / size + 1) : (l / size);
        pageObj.setPageCount((int) l1);
        return pageObj;
    }
}
